package examples.jsf.lifecycle.impl;

import examples.jsf.FacesException;
import examples.jsf.component.UIComponent;
import examples.jsf.component.UIViewRoot;
import examples.jsf.context.FacesContext;
import examples.jsf.event.PhaseId;

import java.util.logging.Level;

/**
 * @author Bill
 * @version 2013-05-29
 */
public class InvokeApplicationPhase extends Phase {
    @Override
    public void execute(FacesContext context) throws FacesException {
        UIViewRoot root = context.getViewRoot();

        if (null == root) {
            throw new IllegalArgumentException("viewRoot not found.");
        }

        try {
            root.processApplication(context);
        } catch (RuntimeException re) {
            String exceptionMessage = re.getMessage();
            if (null != exceptionMessage) {
               // log it
            }
            throw new FacesException(exceptionMessage, re);
        }

        // log line
    }

    @Override
    public PhaseId getId() {
        return PhaseId.INVOKE_APPLICATION;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
